
#include "StaticSprite.h"
#include "DynamicSprite.h"
#include "Projectile.h"
#include "Circle.h"
#include "GameEngine.h"
#include "Ball.h"

using namespace std;
using namespace gaim;

void up();
void down();

int main( int argc, char* args[] )
{
    
    Image im, im2;
    Image im3 = Image("trollface.png", true);
    
    im2 = im;
    im = im3;
    
    Image i1("trollface.png", false);
    
    map<string, Image> m1;
    m1.insert(pair<string, Image>("troll", i1));

    

    
    Image i2("border.jpg", true);
    map<string, Image> m2;
    m2.insert(pair<string, Image>("border", i2));
    Sprite* s2 = StaticSprite::getInstance(m2, "border", Point2(380, 0), 1, true);
    
     Image i3("border.jpg", true);
    map<string, Image> m3;
    m3.insert(pair<string, Image>("border", i3));
    Sprite* s3 = StaticSprite::getInstance(m3, "border", Point2(0, 0), 1, true);
    
    
     Image i4("borderf.jpg", true);
    map<string, Image> m4;
    m4.insert(pair<string, Image>("borderf", i4));
    Sprite* s4 = StaticSprite::getInstance(m4, "borderf", Point2(20, 0), 1, true);
    
    
      Image i5("borderf.jpg", true);
    map<string, Image> m5;
    m5.insert(pair<string, Image>("borderf", i5));
     Sprite* s5 = StaticSprite::getInstance(m5, "borderf", Point2(0, 380), 1, true);
    
 
    Image i6("BOLL.jpg", true);
    
    map<string, Image> m6;
    m6.insert(pair<string, Image>("boll", i6));    
    
    Ball* b = Ball::getInstance(Point2(100,30), m6, false);

    
    
    Sprite* s1 = DynamicSprite::getInstance(m1, "troll", Point2(1, 1), 1, true);
    
    
    dynamic_cast<DynamicSprite *>(s1)->setVel(Vector2(300, 300));
    
    dynamic_cast<DynamicSprite *>(b)->setVel(Vector2(90, 90));
    
    GameEngine ge(30, 100, 100, 400, 400);
    
    ge.registerEvent("key up space", up);
    ge.registerEvent("key down space", down);
    
  //  ge.add(s1);
    ge.add(s2);
       ge.add(b);
    
    ge.add(s3);
    ge.add(s4);
    ge.add(s5);

    ge.run();
    
    return 0;
}

void up(){
     cout << "up" << endl;
}

void down(){
     cout << "down" << endl;
}


/*

Gammalt


#include "StaticSprite.h"
#include "DynamicSprite.h"
#include "Projectile.h"
#include "Circle.h"
#include "GameEngine.h"
#include "Image.h"


#include "SDL/SDL.h"

using namespace std;
//using namespace gaim;

int main( int argc, char* args[] ){
    
    
    /*
    cout << "sprite-test" << endl;

    Image id("apa", false), id2("apa2", true);
    
    map<string, Image> m1, m2;
    
    //m1.insert(pair<string, Image>("apa", id));
    
    map<string, Point2> m3;
    
    m3.insert(pair<string, Point2>("",Point2(1,1)));
    
    int i;
    
    cout << "apapapa" << endl;
    
    cin >> i;
    
    //id2 = id;
    
    

    m1.insert(make_pair("apa", id));
    
    /*

    m2.insert(make_pair("apa", id));
    m2.insert(make_pair("apa2", id2));
    
    /*

    StaticSprite* a = StaticSprite::getInstance(m1, "apa", Point2(0,0), 0);
    cout << *a << endl;
    a->place(1, 2);
    cout << a->getPos() << endl;
    a->place(Point2(3, 7));
    cout << a->getPos() << endl;

    DynamicSprite* b = DynamicSprite::getInstance(m2, "apa2", Point2(2, 7.4), 1);
    cout << *b << endl;
    b->move(Vector2(1, 1));
    cout << b->getPos() << endl;
    b->setVel(Vector2(5, 0));
    b->accelerate(Vector2(0, 1));
    cout << b->getVel() << endl;
    b->move(b->getVel());
    cout << b->getPos() << endl;
    b->place(2.2, 6.6);
    b->move(-0.2, -0.6);
    cout << b->getPos() << endl;

    Vector2 v(2, 1);
    cout << v * 2 << endl << v / 2 << endl;
    cout << 2 * v << endl;

    set<Sprite*> allSprites;
    allSprites.insert(a);
    allSprites.insert(b);

    cout << *(allSprites.begin()) << endl;

    a->place(Point2(0, 0));
    b->place(Point2(0, 0));
    Rectangle* r = Rectangle::getInstance(a->getPos(), 5, 5);

    cout << r->contains( a->getPos() + Vector2(5,5)) << " " << r->bottomRight() << endl;
    cout << r->overlaps(Rectangle::getInstance(Point2(5,4), 1, 1)) << " " << (a->getShape())->getPos() << endl;

    cout << endl << "uppdateringstest:" << endl;
    b->update(allSprites, 1);

    set<Sprite*> someSprites = b->checkCollisions(allSprites);

    cout << *(someSprites.begin()) << endl << *b << endl;

    cout << typeid(b->getImages()).name();
    b->getImages().find("apa");
    b->setImage("apa");

    b->draw(new SDL_Surface());

    Sprite* apapapap = Projectile::getInstance(m1, "apa", Point2(0,0), Vector2(10, 1.2), 5);

    //GameEngine ge(1, 400, 400, 0, 0);
    
    //ge.run();
    
    
    //The images
    SDL_Surface* hello = NULL;
    SDL_Surface* screen = NULL; 
    
    //Start SDL
    SDL_Init( SDL_INIT_EVERYTHING );
    
    //Set up screen screen = SDL_SetVideoMode( 640, 480, 32, SDL_SWSURFACE );
    
    //Load image
    hello = SDL_LoadBMP( "hello.bmp" ); 
    
    //Apply image to screen
    SDL_BlitSurface( hello, NULL, screen, NULL );
    
    //Update Screen
    SDL_Flip( screen );
    
    //Pause
    SDL_Delay( 2000 ); 
    
    //Free the loaded image
    SDL_FreeSurface( hello );
    
    //Quit SDL
    SDL_Quit();
    
    return 0;
}

*/

